#include "huffman.h"


#include <fstream>
#include <sstream>


class node {
public:
    int value;
    int appearences;
    class node *left;
    class node *right;

    node() { left=right=NULL; }
    bool isLeaf() { return left==NULL && right==NULL; }
};

huffman::huffman()
{
}

std::string huffman::constructFilename(char *original)
{
    std::string str=original;
    str+=".huf";
    return str;
}


bool huffman::compress(char *filename, char *newfilename)
{
    std::string outFilename;

    if (newfilename==NULL)
        outFilename=constructFilename(filename);
    else
        outFilename=newfilename;
    std::ifstream::pos_type size;
    unsigned char * memblock;
    std::ifstream infile (filename, std::ios::in|std::ios::binary|std::ios::ate);
    std::ifstream outfile (outFilename.c_str(), std::ios::in|std::ios::binary|std::ios::ate);
    if (outfile.is_open())
    {
        std::cerr << "File " << outFilename << " already exists. Won't overwrite, aborting...";
        return false;
    }
    outfile.close();
    outfile.open(outFilename.c_str(), std::ios::out|std::ios::binary|std::ios::ate);
    if (!infile.is_open())
    {
        std::cerr << "Can't open file " << filename << " , aborting...";
        return false;
    }
}
